<?php
defined('_JEXEC') or die;

class ExercisesController extends JControllerLegacy
{
	public function display($cachable = false, $urlparams = false)
	{
		require_once JPATH_COMPONENT.'/helpers/exercises.php';
		ExercisesHelper::updateReset();

		// Load the submenu.
		//ExercisesHelper::addSubmenu(JRequest::getCmd('view', 'exercises'));

		$view	= JRequest::getCmd('view', 'exercises');
		$layout = JRequest::getCmd('layout', 'default');
		$id		= JRequest::getInt('id');

		// Check for edit form.
		if ($view == 'exercise' && $layout == 'edit' && !$this->checkEditId('com_exercises.edit.exercise', $id)) {

			// Somehow the person just went to the form - we don't allow that.
			$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect(JRoute::_('index.php?option=com_exercises&view=exercises', false));

			return false;
		}
//		elseif ($view == 'client' && $layout == 'edit' && !$this->checkEditId('com_exercises.edit.client', $id)) {
//
//			// Somehow the person just went to the form - we don't allow that.
//			$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
//			$this->setMessage($this->getError(), 'error');
//			$this->setRedirect(JRoute::_('index.php?option=com_exercises&view=clients', false));
//
//			return false;
//		}

		parent::display();

		return $this;
	}
}
